package cn.appsys.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import cn.appsys.biz.BackendUserBiz;
import cn.appsys.biz.DevUserBiz;
import cn.appsys.entity.BackendUser;
import cn.appsys.entity.DevUser;

@Controller
public class IndexController {
	@Autowired
	DevUserBiz devUserBiz;
	@Autowired
	BackendUserBiz backendUserBiz;
	@RequestMapping("/index")
	public String index(){
		return "index";
	}
	@RequestMapping("/backendlogin")
	public String backendLogin(){
		return "backendlogin";
	}
	@RequestMapping("/devlogin")
	public String devLogin(){
		return "devlogin";
	}
	@RequestMapping("/home")
	public String home(){
		return "home";
	}
	
	@RequestMapping(value="/dodevlogin",method=RequestMethod.POST)
	public String dodevlogin(String devName,String devPassword,HttpSession session,Model model){
		
		DevUser devUser = devUserBiz.login(devName, devPassword);
		System.out.println(devUser.getDevName());
		if(devUser!=null){
			session.setAttribute("devUser", devUser);
			return "redirect:/home";
		}
		else{
			model.addAttribute("error", "账号或者密码错误");
			return "/devlogin";
		}
		
	}
	@RequestMapping(value="/dobaclogin",method=RequestMethod.POST)
	public String dobaclogin(String userName,String userPassword,HttpSession session,Model model){
		System.out.println(userName+userPassword);
		BackendUser backendUser = backendUserBiz.login(userName, userPassword);
		System.out.println(backendUser.getUserName());
		if(backendUser!=null){
			session.setAttribute("backendUser", backendUser);
			return "redirect:/home";
		}
		else{
			model.addAttribute("error", "账号或者密码错误");
			return "/devlogin";
		}
		
	}
}
